from flask import Blueprint, jsonify
from dao.ProblemDao import ProblemDAO

problem_bp = Blueprint('problem', __name__, url_prefix='/problem')

problem_dao = ProblemDAO()


@problem_bp.route('/getAll', methods=['GET'])
def get_all():
    problems = problem_dao.select_all()
    return jsonify(problems)


@problem_bp.route('/getOne/<int:id>', methods=['GET'])
def get_one(id):
    problem = problem_dao.select_one(id)
    if problem:
        return jsonify(problem.to_dict())
    return jsonify({"error": "Problem not found"}), 404
